const localStorage = {
  get(key: string) {
    const value = window.localStorage.getItem(key)

    return value ? JSON.parse(value) : null
  },
  set(key: string, value: Record<string | number, any> | string) {
    window.localStorage.setItem(key, JSON.stringify(value))
    return value
  },
  remove(key: string) {
    window.localStorage.removeItem(key)
  },
  removeAll() {
    window.localStorage.clear()
  }
}

const sessionStorage = {
  get(key: string) {
    const value = window.sessionStorage.getItem(key)

    return value ? JSON.parse(value) : null
  },
  set(key: string, value: Record<string | number, any> | string) {
    !!value && window.sessionStorage.setItem(key, JSON.stringify(value))
    return value
  },
  remove(key: string) {
    window.sessionStorage.removeItem(key)
  },
  removeAll() {
    window.sessionStorage.clear()
  }
}

export default {
  localStorage,
  sessionStorage
}